CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later


If GetOemLed (825)=0 Then 'Check to see if the probe is already grounded or faulty
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P2" ' two second delay
Code "G31 Z-1.0 F5" 'Z goes down a max of 1.0 at 5IPM
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the axact point the probe was hit
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of overrun
While IsMoving ()
Wend
Call SetDro (2,0.000) 
Code "G4 P0.25" 'Pause for Dro to update.
Code "G90 G0 Z.500" 'retract Z to .500 inch
Code "G91 G0 Y-.100 X.750"
Code "G90 G0 Z-.200"
Code "F" &CurrentFeed 'Returns to prior feed rate
Else
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
Exit Sub
End If

Rem	VBScript For probing In the x- direction

If GetOemLed (825)=0 Then 		'Check to see if the probe is already grounded or faulty
	Code "(Probe plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
Else
	Code "G4 P1"			'Pause 1 second to give time to position probe plate

	CurrentFeed = GetOemDRO(818) 	'Get the current feedrate to return to later
	Code "F4"

Rem	Probe Left

	XNew = GetDro(0) - 3		'probe to current position - 3 inches
	Code "G31 X" &XNew
	While IsMoving()		'wait for prob move to complete
	Wend
	XNew = GetVar(2000)		'read the touch point

Rem	move back To the hit point incase there was an overshoot

	Code "G90 G0 Z.500"
	Code "G90 G0 X" &XNew
	Code "G91 X-.100"
        
	
	While IsMoving ()
	Wend
        Call SetDro (0,0.000)
        Code "G4 P0.25" 
        Code "G91 G0 X-.200 Y.750"
        Code "G90 G0 Z-.200"
	Code "F" &CurrentFeed 		'restore original feed rate
End If 

Rem	VBScript For probing In the Y direction

If GetOemLed (825) <> 0 Then 		'Check to see if the probe is already grounded or faulty
	Code "(Probe plate is grounded, check connection and try again)"
Else
	Code "G4 P1"			'Pause 1 second to give time to position probe plate

	CurrentFeed = GetOemDRO(818) 	'Get the current feedrate to return to later
	Code "F4"			'Slow feedrate to 4 ipm

Rem	Probe up

	YNew = GetDro(1) - 3		'move to current y position + 3 inches
	Code "G31 Y" &YNew
	While IsMoving()		'wait for the move to finish
	Wend
	YNew = GetVar(2001)		'read the touch point

Rem	move back to the hit point incase there was an overshoot
	
        Code "G90 G0 Z.500"
	Code "G90 G0 Y" &YNew
        Code "G91 Y.100"

	While IsMoving ()
	Wend
        Call SetDro (1,0.000)
        Code "G4 P0.25"
        Code "G90 G0 X0.0"
	Code "F" &CurrentFeed 		'restore original feed rate
        Code "(X, Y, and Z axis' are now zeroed)"
End If
